class Solution:
    def minNumberOfFrogs(self, croakOfFrogs: str) -> int:
        croakMap = {'c': 0, 'r': 1, 'o': 2, 'a': 3, 'k': 4}
        counter = [0 for _ in range(5)]
        ans = 0
        for s in croakOfFrogs:
            i = croakMap[s]
            counter[i] += 1
            if i > 0:
                if counter[i] > counter[i - 1]:
                    return -1
            ans = max(ans, counter[croakMap['c']])
            if i == croakMap['k']:
                for i in range(len(counter)):
                    counter[i] -= 1
        for i in range(len(counter)):
            if counter[i] > 0:
                return -1
        return ans
